package com.zzxx.mapper;

import com.zzxx.pojo.UserInfo;
import com.zzxx.pojo.UserRole;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserMapper {
    @Select("select * from users where username = #{username}")
    UserInfo findByUsername(String username);

    @Select("select * from users")
    List<UserInfo> queryAll();

    @Select("select * from users where id = #{id}")
    @Results(value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "username",property = "username"),
            @Result(column = "email",property = "email"),
            @Result(column = "password",property = "password"),
            @Result(column = "phoneNum",property = "phoneNum"),
            @Result(column = "status",property = "status"),
            @Result(column = "id",property = "roles",many = @Many(select = "com.zzxx.mapper.RoleMapper.findByUid"))
    })
    UserInfo findById(String id);

}
